package com.soft.springhrms.controller;

import com.soft.springhrms.pojo.Employees;
import com.soft.springhrms.pojo.Requests;
import com.soft.springhrms.service.EmployeesService;
import com.soft.springhrms.service.PerformancesService;
import com.soft.springhrms.service.RequestsService;
import com.soft.springhrms.service.SalariesService;
import com.soft.springhrms.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee")
@CrossOrigin
public class EmployeeController {
    @Autowired
    private RequestsService requestsService;
    @Autowired
    private EmployeesService employeesService;
    @Autowired
    private SalariesService salariesService;
    @Autowired
    private PerformancesService performanceService;

    // 员工申请加班/请假/离职
    @PostMapping("/requests")
    public ResultVO addRequests(@RequestBody Requests requests) {
        if (requests != null) {
            requestsService.addRequests(requests);
        }
        return ResultVO.success(null, "请求成功");
    }
    // 查询自己的加班/请假/离职申请
    @GetMapping("/checkHistory")
    public ResultVO queryRequests(@RequestParam Integer employeeId, @RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "size", defaultValue = "10") int size) {
        return requestsService.queryRequestsHistory(employeeId, page, size);
    }
    @GetMapping("/{id}")
    public Employees getEmployeeInfo(@PathVariable Integer id){

        return employeesService.getEmployeeInfo(id);
    }

    // 员工查看自己的工资发放历史
    @GetMapping("/getSalaries")
    public ResultVO getSalaries(@RequestParam Integer employeeId, @RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "size",defaultValue = "10") int size){
        return salariesService.querySalariesById(employeeId, page, size);
    }

    // 员工查看自己的绩效考核历史
    @GetMapping("/getPerformance")
    public ResultVO getPerformance(@RequestParam Integer employeeId, @RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "size",defaultValue = "10") int size){
        return performanceService.queryPerformancesById(employeeId, page, size);
    }

}
